package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.Emp;
import cn.gson.springboot.model.pjos.Server;
import cn.gson.springboot.model.service.afterservice.ServerService;
import cn.gson.springboot.model.vo.aftervo.MaintainChartVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/ser")
public class ServerController {

    @Autowired
    ServerService sc;

    @RequestMapping("/sver-page")
    @ResponseBody
    public Map<String,Object> sverPage(Integer states,String search,Integer currPage,Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Server> sver = sc.serverPage(states,search);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;     //总条数
    }

    @RequestMapping("/save-serv")
    @ResponseBody
    public void saveServ(@RequestBody Server serv){
        sc.addServ(serv);
    }

    @RequestMapping("/check-serv")
    @ResponseBody
    public Server checkServ(Integer servId){
        return sc.selectServ(servId);
    }

    @RequestMapping("/check-emp")
    @ResponseBody
    public List<Emp> checkEmp(){
        return sc.selectEmp();
    }

    @RequestMapping("/delete-serv")
    @ResponseBody
    public void deleteServ(Integer servId){
        sc.deleteByServId(servId);
    }

    @RequestMapping("/check-type")
    @ResponseBody
    public List<MaintainChartVo> checkType(){
        return sc.selectServByType();
    }

    @RequestMapping("/check-mode")
    @ResponseBody
    public List<MaintainChartVo> checkMode(){
        return sc.selectServByMode();
    }

    @RequestMapping("/check-date")
    @ResponseBody
    public List<MaintainChartVo> checkDate(){
        return sc.selectServByDate();
    }

    @RequestMapping("/check-customer")
    @ResponseBody
    public List<MaintainChartVo> customerByDate(){
        return sc.selectCustomerByDate();
    }

    @RequestMapping("/serv-month")
    @ResponseBody
    public List<String> servMonth(){
        return sc.selectServiceMonth();
    }

    @RequestMapping("/serv-count")
    @ResponseBody
    public List<Integer> servCount(){
        return sc.selectServiceCount();
    }

    @RequestMapping("/finish-month")
    @ResponseBody
    public List<String> finishMonth(){
        return sc.selectFinishMonth();
    }

    @RequestMapping("/finish-count")
    @ResponseBody
    public List<Integer> finishCount(){
        return sc.selectFinishCount();
    }
}
